namespace CSharpPro._1021;

public class UserServiceImpl
{
    private List<User> _users = new List<User>();
    private int _nextId = 1;
    
    public bool AddUser(User user)
    {
        if (user == null) return false;
        
        user.Id = _nextId++;
        _users.Add(user);
        return true;
    }
    
    public bool DeleteUser(int id)
    {
        var user = _users.FirstOrDefault(u => u.Id == id);
        if (user == null) return false;
        
        return _users.Remove(user);
    }
    
    public bool UpdateUser(User user)
    {
        if (user == null) return false;
        
        var existingUser = _users.FirstOrDefault(u => u.Id == user.Id);
        if (existingUser == null) return false;
        
        existingUser.Name = user.Name;
        existingUser.Email = user.Email;
        return true;
    }
    
    public User GetUserById(int id)
    {
        return _users.FirstOrDefault(u => u.Id == id);
    }
    
    public List<User> GetAllUsers()
    {
        return new List<User>(_users);
    }

}